package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.login.GuiguLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.driver.service.LocationService;
import com.atguigu.daijia.model.form.map.OrderServiceLocationForm;
import com.atguigu.daijia.model.form.map.UpdateDriverLocationForm;
import com.atguigu.daijia.model.form.map.UpdateOrderLocationForm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Tag(name = "位置API接口管理")
@RestController
@RequestMapping(value="/location")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class LocationController {

    private final LocationService locationService;

    /**
     * 司机开始接单，更新司机位置信息
     * @param updateDriverLocationForm
     * @return
     */
    @Operation(summary = "司机开始接单，更新司机位置信息")
    @GuiguLogin
    @PostMapping("/updateDriverLocation")
    public Result<Boolean> updateDriverLocation(@RequestBody UpdateDriverLocationForm updateDriverLocationForm) {
        updateDriverLocationForm.setDriverId(AuthContextHolder.getUserId());
        Boolean result = locationService.updateDriverLocation(updateDriverLocationForm);
        return Result.ok(result);
    }

    /**
     * 接单司机前往代驾订单起始点过程中更新司机位置信息到缓存
     * @param updateOrderLocationForm
     * @return
     */
    @Operation(summary = "接单司机前往代驾订单起始点过程中更新司机位置信息到缓存")
    @GuiguLogin
    @PostMapping("/updateOrderLocationToCache")
    public Result<Boolean> updateDriverLocationToCache(@RequestBody UpdateOrderLocationForm updateOrderLocationForm) {
        Boolean result = locationService.updateDriverLocationToCache(updateOrderLocationForm);
        return Result.ok(result);
    }

    /**
     * 开始代驾服务后，批量保存订单服务过程中司机位置信息
     * @param orderServiceLocationFormList
     * @return
     */
    @Operation(summary = "开始代驾服务后，批量保存订单服务过程中司机位置信息")
    @GuiguLogin
    @PostMapping("/saveOrderServiceLocation")
    public Result<Boolean> batchSaveLocationDuringService(@RequestBody List<OrderServiceLocationForm> orderServiceLocationFormList) {
        Boolean result = locationService.batchSaveLocationDuringService(orderServiceLocationFormList);
        return Result.ok(result);
    }
}

